﻿#ifndef DESIGNMODEL_H
#define DESIGNMODEL_H

#include "ThreadObject.h"
#include <QThread>
#include <QObject>
#include <QVariant>
#include <QJsonObject>

class DesignModel : public QObject
{
    Q_OBJECT

    Q_PROPERTY(bool enable READ enable WRITE setEnable NOTIFY enableChanged)
    Q_PROPERTY(QString startKey READ startKey WRITE setStartKey NOTIFY startKeyChanged)
    Q_PROPERTY(QString stopKey READ stopKey WRITE setStopKey NOTIFY stopKeyChanged)
    Q_PROPERTY(QString sequenceKey READ sequenceKey WRITE setSequenceKey NOTIFY sequenceKeyChanged)
    Q_PROPERTY(QString interval READ interval WRITE setInterval NOTIFY intervalChanged)

public:
    explicit DesignModel(QObject *parent = 0);

    explicit DesignModel(const bool &enable,
                         const int &keyMode,
                         const QString &startKey,
                         const QString &stopKey,
                         const QString &sequenceKey,
                         const QString &interval,
                         QObject *parent = 0);

    bool enable() const;
    void setEnable(const bool &enable);

    bool running() const;
    void setRunning(const bool &running);

    QString startKey() const;
    void setStartKey(const QString &startKey);

    QString stopKey() const;
    void setStopKey(const QString &stopKey);

    QString sequenceKey() const;
    void setSequenceKey(const QString &sequenceKey);

    QString interval() const;
    void setInterval(const QString &interval);

    int keyMode() const;

    void read(const QJsonObject &json);
    void write(QJsonObject &json) const;

signals:
    void enableChanged();
    void startKeyChanged();
    void stopKeyChanged();
    void sequenceKeyChanged();
    void intervalChanged();

public:
    QThread *mQThread;
    ThreadObject *mThreadObject;

private:
    bool m_enable = false;
    bool m_running = false;
    int m_keyMode;
    QString m_startKey;
    QString m_stopKey;
    QString m_sequenceKey;
    QString m_interval;
};
#endif // DESIGNMODEL_H
